<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/4
 * Time: 12:44
 */
namespace app\admin\controller;
use think\Controller;
use thiNK\Request;
use think\Session;

class Login extends Controller
{
    public function login(){
        if(Request::instance()->isPost()){
            $name = input('post.name');
            $pass = md5(input('post.pass'));
            $admin = db('admin')->where(['name'=>$name,'pass'=>$pass])->find();
            if($admin){
                Session::set('admin',$admin);
                $data['login_ip'] = Request::instance()->ip();
                $data['last_time'] = date("Y-m-d H:i:s");
                $data['on_line'] = time() + 600;
                db('admin')->where('id',$admin['id'])->update($data);
                $this->success('登录成功!','Index/index','',1);
            }else{
                $this->error('账号或密码错误!');
            }
        }
        return $this->fetch();
    }
}


